import Toast from 'tdesign-miniprogram/toast/index';



Page({
  data: {
    userInfo: {
      userType: -1
    },
    isEnable: false,
    menuData: []
  },

  onLoad() {

  },

  onShow() {
    this.getTabBar().init();
    this.init();
  },
  onPullDownRefresh() {
    this.init();
  },

  init() {
    const userInfo = getApp().globalData.userInfo;
    console.log("init", userInfo)
    if (userInfo != null) {
      this.setData({ userInfo: userInfo, isEnable: userInfo.flag == 1 })
    }
    if (this.data.userInfo.userType == -1) {
      wx.navigateTo({
        url: '/pages/usercenter/register/index?userType=-1'
      });
    }
  },

  // registerBusiness() {
  //   wx.navigateTo({
  //     url: 'register/index?userType=1',
  //   })
  // },
  // registerappraiser() {
  //   wx.navigateTo({
  //     url: 'register/index?userType=0',
  //   })
  // },


  onClickCell({
    currentTarget
  }) {
    const {
      type
    } = currentTarget.dataset;

    switch (type) {
      case 'moneylist': {
        wx.navigateTo({
          url: '/pages/usercenter/money/list/index'
        });
        break;
      }
      case 'paimai': {
        wx.navigateTo({
          url: '/pages/usercenter/auction/index'
        });
        break;
      }
      case 'carlist': {
        wx.navigateTo({
          url: '/pages/usercenter/carlist/index'
        });
        break;
      }
      case 'switchuser': {
        this.setData({
          userInfo: {
            userType: -1
          }
        });
        wx.clearStorage();
        break;
      }
      case 'address': {
        wx.navigateTo({
          url: '/pages/usercenter/address/list/index'
        });
        break;
      }
      case 'service': {
        this.openMakePhone();
        break;
      }
      case 'point': {
        Toast({
          context: this,
          selector: '#t-toast',
          message: '你点击了积分菜单',
          icon: '',
          duration: 1000,
        });
        break;
      }
      case 'coupon': {
        wx.navigateTo({
          url: '/pages/coupon/coupon-list/index'
        });
        break;
      }
      default: {
        Toast({
          context: this,
          selector: '#t-toast',
          message: '未知跳转',
          icon: '',
          duration: 1000,
        });
        break;
      }
    }
  },

  adminLogin() {
    var admin_token = wx.getStorageSync('admin_token');
    if (admin_token != null && admin_token != '') {
      var userInfo = wx.getStorageSync('admin_userInfo');
      getApp().globalData.admin = JSON.parse(userInfo);
      wx.redirectTo({
        url: '/pages/admin/usercenter/index',
      })
    } else {
      wx.navigateTo({
        url: '/pages/admin/login/index'
      });
    }

  },

  openMakePhone() {
    this.setData({
      showMakePhone: true
    });
  },

  closeMakePhone() {
    this.setData({
      showMakePhone: false
    });
  },

  call() {
    wx.makePhoneCall({
      phoneNumber: getApp().globalData.servicePhone,
    });
  },

  gotoUserEditPage() {
    const {
      currAuthStep
    } = this.data;
    if (currAuthStep === 2) {
      wx.navigateTo({
        url: '/pages/usercenter/person-info/index'
      });
    } else {
      this.fetUseriInfoHandle();
    }
  },


});